//
//  BLOrderPearlVC.m
//  Byelone
//
//  Created by 乔小乔 on 2021/2/6.
//

#import "BLOrderPearlVC.h"
#import "BLOrder_Cell_Pearl.h"
#import "BLOrder_Cell_Shell.h"
static NSString *reuse_BLOrder_Cell_Pearl = @"Reuse_BLOrder_Cell_Pearl";
static NSString *reuse_BLOrder_Cell_Shell = @"Reuse_BLOrder_Cell_Shell";
@interface BLOrderPearlVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableViewList;
@property (nonatomic, strong) NSMutableArray *arrayData;
@end

@implementation BLOrderPearlVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.arrayData = [[NSMutableArray alloc]init];
    [self getData];
}

- (void)getData{
    [BLHttpTool getHttpRequest:BL_USER_RECORDLIST param:@{@"giftType":@(self.giftType)} finish:^(NSURLSessionDataTask * _Nonnull data, NSDictionary * _Nonnull obj) {
        [self.tableViewList.mj_header endRefreshing];
        [self.tableViewList.mj_footer endRefreshing];
        BLOrderOtherModel *model = [BLOrderOtherModel mj_objectWithKeyValues:obj[@"content"]];
        [self.arrayData removeAllObjects];
        [self.arrayData addObjectsFromArray:model.list];
        [self.tableViewList reloadData];
    } failedBlock:^(id  _Nonnull data, NSError * _Nonnull error) {
        [self.tableViewList.mj_header endRefreshing];
        [self.tableViewList.mj_footer endRefreshing];
    }];
}
- (void)refreshData{
    [self getData];
}
#pragma mark - delegate

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arrayData.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    BLOtherItem *dict = self.arrayData[indexPath.row];
    if (self.giftType == 1) {
        BLOrder_Cell_Pearl *cell = [tableView dequeueReusableCellWithIdentifier:reuse_BLOrder_Cell_Pearl forIndexPath:indexPath];
        
        [cell reloadWith:dict];
        return cell;
    }else{
        BLOrder_Cell_Shell *cell = [tableView dequeueReusableCellWithIdentifier:reuse_BLOrder_Cell_Shell forIndexPath:indexPath];
        
        [cell reloadWith:dict];
        return cell;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.giftType == 1) {
        return 92;
    }
    return 61;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
#pragma mark - set&get
- (UITableView *)tableViewList{
    if (!_tableViewList) {
        _tableViewList = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, BL_WINDOW_WIDTH, BL_CONTENT_HEIGHT-48)];
        [self.view addSubview:_tableViewList];
        _tableViewList.backgroundColor = [UIColor clearColor];
        _tableViewList.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableViewList.delegate = self;
        _tableViewList.dataSource = self;
        if (@available(iOS 11.0, *)) {
            _tableViewList.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else{
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
        [_tableViewList registerNib:[UINib nibWithNibName:@"BLOrder_Cell_Pearl" bundle:nil] forCellReuseIdentifier:reuse_BLOrder_Cell_Pearl];
        [_tableViewList registerNib:[UINib nibWithNibName:@"BLOrder_Cell_Shell" bundle:nil] forCellReuseIdentifier:reuse_BLOrder_Cell_Shell];
        _tableViewList.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(refreshData)];
        
//        _tableViewList.tableFooterView = self.viewFooter;
    }
    return _tableViewList;
}

@end
